package com.k1ccc0.alumniinformationmanagement.mapper;

import com.k1ccc0.alumniinformationmanagement.pojo.Alumni;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface AlumniMapper {
    List<Alumni> list(String name, String username, Short gender,  String major, String department,
                      String nativePlace, String phoneNumber, String email);
    //登录 根据用户名和密码查询
    @Select("select * from alumni where username = #{username} and password = #{password}")
    Alumni getUsernameAndPassword(Alumni alumni);


    void update(Alumni alumni);

    @Select("select * from alumni where username = #{username}")
    Alumni getByUsername(String username);

    @Select("select id, name, username from alumni where username = #{username}")
    Alumni selectUserInfoByUAndP(String username);

    @Update("update alumni set image = #{image} where username = #{username}")
    void updateAvatar(Alumni alumni);

    @Update("update alumni set username = #{username} where id = #{id}")
    void updateUsernameById(Alumni alumni);
    @Update("update alumni set password = #{password} where id = #{id}")
    void updatePasswordById(Alumni alumni);
    @Insert("insert into alumni(name, username, password, gender, enrollment_date, graduation_date, birth_date, major, department, native_place, phone_number, email)" +
            "values (#{name},#{username},#{password},#{gender},#{enrollmentDate},#{graduationDate},#{birthDate},#{major},#{department},#{nativePlace},#{phoneNumber},#{email})")
    void add(Alumni alumni);

    void deleteById(List<Integer> ids);
    
    @Select("SELECT id, name, department, major, latitude, longitude FROM alumni WHERE latitude IS NOT NULL AND longitude IS NOT NULL")
    List<Alumni> getAllLocations();
}
